#!/bin/bash
# SimpleMake安装脚本

target=/usr/local/bin/SimpleMake
ln_target=/usr/local/bin/smake

# 需要root权限
if [ `whoami` != "root" ]; then
    echo "Need root authorization"
    exit 1
fi

files="src/Utility.py \
src/smake_db.py \
src/lazy_judge.py \
src/dag.py \
src/cmd_runner.py \
src/config_schema.py \
src/SimpleMakeConfig.py \
src/Builder.py \
src/SimpleMake.py"

echo "#!/usr/bin/env python3
import os
import os.path
import shutil
import logging
import hashlib
import copy
import subprocess
import threading
import queue
import json
import jsonschema
from jsonc_parser.parser import JsoncParser
from multiprocessing import cpu_count
import argparse
import sys
" > $target

# 把多个.py文件合成一个文件
for f in $files;
do
    line=`grep -n "# ===CODE===" $f | cut -d ':' -f 1`
    line=`expr $line + 1`
    sed -n "${line},\$p" $f >> $target
done
rm -f $ln_target
ln -s $target $ln_target

# 授权
chmod 777 $target
chmod 777 $ln_target

echo "SimpleMake/smake install success."

